package com.braincookie.plugins.jira.tabpanels.utils;


import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.issue.search.SearchRequest;



public class SearchFilterRequestViewUtils
{

    public static String getLink(final SearchRequest searchRequest, final String baseUrl, final User user, SearchService searchService)
    {
        final StringBuilder link = new StringBuilder(baseUrl).append("/secure/IssueNavigator.jspa?");
        if (searchRequest != null && searchRequest.getId() != null)  // TODO: Why would searchRequest be null?
        {
            link.append("requestId=").append(searchRequest.getId());
        }
        else if (searchService != null)
        { 
            link.append("reset=true").append(searchService.getQueryString(user, searchRequest.getQuery()));
        } else {
        	link.append("error=searchService is null");
        }

        return link.toString();
    }
}